package com.infore.airsupervise.ui.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.beardedhen.androidbootstrap.AwesomeTextView;
import com.infore.airsupervise.R;
import com.infore.airsupervise.utils.TitleBarHelper;

/**
 * 带标题栏的Activity 基类
 *
 * @作者: dingxinlin
 * @创建时间: 2017/3/23 13:35
 */
public class BaseTitleBarActivity extends BaseActivity {

    protected TextView title;
    protected AwesomeTextView leftMenu;
    protected AwesomeTextView rightMenu;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public void setContentView(int layoutResID) {
        // 初始化titleBarHelper
        TitleBarHelper titleBarHelper = new TitleBarHelper(this, layoutResID);

        // 实例titleBar中的控价
        View titleBar = titleBarHelper.getTitleBar();
        title = (TextView) titleBar.findViewById(R.id.titlebar_title);
        leftMenu = (AwesomeTextView) titleBar.findViewById(R.id.titlebar_left_menu);
        rightMenu = (AwesomeTextView) titleBar.findViewById(R.id.titlebar_right_menu);

        // 设置菜单点击监听
        leftMenu.setOnClickListener(menuClickListener);
        rightMenu.setOnClickListener(menuClickListener);

        // 设置容器视图
        setContentView(titleBarHelper.getContentView());
    }

    /**
     * 菜单点击监听
     */
    private View.OnClickListener menuClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (view == leftMenu) {
                onLeftMenuClick(view);
            } else {
                onRightMenuClick(view);
            }
        }
    };

    protected void onLeftMenuClick(View view) {
        finish();
    }

    protected void onRightMenuClick(View view) {}
}
